package com.example.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class GetCode {

	// 生成 订单号
	public static String getCode(Date createTime,int num) {
		String code = new SimpleDateFormat("yyyyMMddHHmmss").format(createTime)
				+ getRandomNum(num);
		return code;
	}

	public static String getRandomNum(int num) {
		int maxNum = 36;
		int i;
		int count = 0;
		char[] str = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
		StringBuffer pwd = new StringBuffer();
		Random r = new Random();
		while (count < num) {
			i = Math.abs(r.nextInt(maxNum));
			if (i >= 0 && i < str.length) {
				pwd.append(str[i]);
				count++;
			}
		}
		return pwd.toString();
	}

	public static void main(String[] args) {
		try {
			System.out.println(getCode(new Date(),4).length());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
